<?php
$aMenuPosition = unserialize(PAGE_POSITION_TEXT);
$aPageTemplateName = getTemplateName(PAGE_TEMPLATE_DIR);
?>
<div class="row">
	<div class="col-md-12">
		<h1>Trang <small>Quản lý các trang trên Menu chính, footer</small></h1>
		<ol class="breadcrumb">
            <li><a href="<?php echo admin_page_url(); ?>"><i class="fa fa-dashboard"></i> Dashboard</a></li>
            <li class="active"><i class="fa fa-table"></i> Danh sách các trang hiện có</li>
        </ol>
    </div>
</div>

<div class="row">
    <div class="col-md-12">
        <p class="pull-right">
            <a class="btn btn-success" href="<?php echo admin_page_url(PAGE_SLUG . '/them-moi'); ?>">
                <i class='glyphicon glyphicon-plus-sign'></i>&nbsp;Thêm trang
            </a>
        </p>
    </div>
    <div class="col-md-12">
        <div class="table-responsive">
            <table class="table table-bordered table-hover tablesorter item-list" data-href='<?php echo admin_page_url(PAGE_SLUG.'/cap-nhat/do'); ?>'>
                <thead>
                    <tr>
                        <th class="header"># <i class="fa fa-sort"></i></th>
                        <th class="header">Tên trang / Đường dẫn <i class="fa fa-sort"></i></th>
                        <th class="header">Nhóm menu <i class="fa fa-sort"></i></th>
                        <th class="header">Thứ tự <i class="fa fa-sort"></i></th>
                        <th class="header">Nội dung <i class="fa fa-sort"></i></th>
                        <th class="header">Template <i class="fa fa-sort"></i></th>
                        <th class="header">&nbsp;</th>
                    </tr>
                    <tr class="tr-temp hidden warning">
                        <td colspan="9">
                            <form role="form" method="post" data-callback='1'>
                                <div class="form-group col-md-6 col-xs-12">
                                    <label for="input-page-title">Tên trang</label>
                                    <input type="text" class="form-control auto-slug" follow-ctr='#input-page-slug' id="input-page-title" name="page[title]" value="" />
                                </div>
                                <div class="form-group col-md-6 col-xs-12">
                                    <label for="input-page-slug">Đường dẫn</label>
                                    <input type="text" class="form-control" id="input-page-slug" name="page[slug]" value="" />
                                </div>

                                <div class="col-md-3 col-xs-12">
                                    <div class="form-group">
                                        <label for="input-page-position">Nhóm menu</label>
                                        <select class="form-control" id="input-page-position" name="page[position]">
                                            <?php foreach($aMenuPosition as $key=>$text){ ?>
                                            <option value="<?php echo $key; ?>"><?php echo $text; ?></option>
                                            <?php } ?>
                                        </select>
                                    </div>
                                    <div class="form-group">
                                        <label for="input-page-order">Thứ tự trên menu</label>
                                        <input type="text" class="form-control" id="input-page-order" name="page[order]" value="" />
                                    </div>
                                    <div class="form-group">
                                        <label for="input-page-template">Tên file template thay thế</label>
                                        <select class="form-control" id="input-page-template" name="page[template]">
                                            <option value="">-</option>
                                            <?php foreach($aPageTemplateName as $pn) { ?>
                                            <option value="<?php echo $pn; ?>"><?php echo $pn; ?></option>
                                            <?php } ?>
                                        </select>
                                    </div>
                                </div>

                                <div class="form-group col-md-6 col-xs-12">
                                    <label for="input-page-content">Nội dung trang</label>
                                    <textarea class="form-control" id="input-page-content" name="page[content]" rows="8"></textarea>
                                </div>

                                <div class="col-md-3 col-xs-12">
                                    <div class="checkbox">
                                        <label for="input-page-publish-flg">
                                            <input type="checkbox" id="input-page-publish-flg" name="page[publish_flg]" value="1" />Hiển thị
                                        </label>
                                    </div>
                                    <div class="checkbox">
                                        <label for="input-page-delete-flg">
                                            <input type="checkbox" id="input-page-delete-flg" name="page[delete_flg]" value="1"/> Xoá
                                        </label>
                                    </div>
                                    <div>
                                        <input type="hidden" name="page[case]" value="<?php echo UPDATE_FULL; ?>" />
                                        <input type="hidden" name="page[id]" id="input-page-id" />
                                        <button type="button" class="btn btn-success btn-submit-update"><i class='glyphicon glyphicon-ok-sign'></i>&nbsp;Cập nhật</button>
                                        <button type="button" class="btn btn-danger btn-cancel-update"><i class='glyphicon glyphicon-remove-sign'></i>&nbsp;Huỷ</button>
                                    </div>
                                </div>
                            </form>
                        </td>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach($aPage as $index=>$page) { ?>
                    <tr class="can-edit" data-id="<?php echo $this->encrypt->encode($page->getId()); ?>">
                        <th class="header bg-info"><?php echo $index+1; ?></th>
                        <td>
                            <p class="input-page-title strong big-title">
                                <a href="<?php echo admin_page_url(PAGE_SLUG.'/'.$page->getSlug().'/cap-nhat'); ?>">
                                    <?php echo $page->getTitle(); ?>
                                </a>
                            </p>
                            <p class="input-page-slug">
                                <a class="btn btn-success" data-slug=' <?php echo $page->getSlug(); ?>' target="_blank" href="<?php echo page_url($page->getSlug()); ?>">
                                    <i class="glyphicon glyphicon-share-alt"></i> Xem
                                </a>
                            </p>
                        </td>
                        <td class="input-page-position" data-position='<?php echo $page->getPosition(); ?>'>
                            <h4><label class="label label-danger"><?php echo $aMenuPosition[$page->getPosition()]; ?></label></h4>
                        </td>
                        <td class="input-page-order strong"><?php echo $page->getOrder(); ?></td>
                        <td class="input-page-content">
                            <textarea class="form-control" readonly="readonly"><?php echo $page->getContent(); ?></textarea>
                        </td>
                        <td class="input-page-template"><?php echo $page->getTemplate(); ?></td>
                        <td>
                            <p class="input-page-publish-flg">
                                Hiển thị
                                <input id="chk-pub-<?php echo $index+1; ?>" class="checkbox lb-toggle" data-name="publish_flg" type="checkbox" <?php echo ($page->getPublishFlg())==1?"checked='checked'":''; ?> />
                                <label for="chk-pub-<?php echo $index+1; ?>"></label>
                            </p>
                            <hr class="clearPad clearMgr mgt5 mgbt5"/>
                            <p class="input-page-delete-flg">
                                Xóa
                                <input id="chk-del-<?php echo $index+1; ?>" class="checkbox lb-toggle red" data-name="delete_flg" type="checkbox" <?php echo ($page->getDeletedAt())!=NULL?"checked='checked'":''; ?> />
                                <label for="chk-del-<?php echo $index+1; ?>"></label>
                            </p>
                            <p>
                                <a class="btn btn-success" href="<?php echo admin_page_url(PAGE_SLUG.'/'.$page->getSlug().'/cap-nhat/'); ?>">
                                    <i class="glyphicon glyphicon-pencil"></i>
                                    Sửa
                                </a>
                            </p>
                        </td>
                    </tr>
                    <?php } ?>
                </tbody>
            </table>
        </div>
    </div>
    <div class="clearfix"></div>
</div>